package com.qfedu.springmvc02.utils;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

import java.io.IOException;
import java.lang.reflect.Type;
import java.math.BigDecimal;

public class SalarySerialize implements ObjectSerializer {
    @Override
    public void write(JSONSerializer jsonSerializer, Object o, Object o1, Type type, int i) throws IOException {
        double salary = (double)o;
        String s = BigDecimal.valueOf(salary).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
        jsonSerializer.write(s + "元");
    }
}
